<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>条件渲染 - 广告</title>
    <style>
        .ad{
            width: 100%;
            height: 80px;
            text-align:center;
            line-height: 80px;
            background-color: #cae;
        }
    </style>
</head>
<body>
    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        //数据
        let data = {
            isVip: true
        }

        //声明一个函数
        function showAd(){
            if(data.isVip){
                return null;
            }else{
                return <div className="ad">广告</div>;
            }
        }

        //创建虚拟 DOM
        let vDOM = <header>
                {/*1. 逻辑与运算符*/}
                {/*{!data.isVip && <div className="ad">广告</div>}*/}   
                {/*2. 三目运算符  三元运算符*/}
                {/* {data.isVip ? null : <div className="ad">广告</div>} */}
                {/*3. if 在函数中使用*/}
                {showAd()}
        </header>;

        //渲染
        ReactDOM.render(vDOM, document.querySelector("#root"));
    </script>

</body>
</html>